package com.wangcang.widgetlibrary.list;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.wangcang.widgetlibrary.R;
import com.wangcang.widgetlibrary.activity.base.BaseActivity;
import com.wangcang.widgetlibrary.adapter.CheckBoxListAdapter;
import com.wangcang.widgetlibrary.bean.SelectBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 多选列表
 * Created by ShineF on 2017/7/12 0012.
 */

public class CheckBoxListActivity extends BaseActivity {

    private TextView mReStart;
    private ListView mLvRadio;
    private TextView mTvTitle;
    private List<SelectBean> dataList;
    ImageView mBackBt;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_checkbox_list);
        init();
    }

    public void init() {
        mReStart = (TextView) findViewById(R.id.tv_restart);
        mLvRadio = (ListView) findViewById(R.id.lv_radio_list);
        mTvTitle = (TextView) findViewById(R.id.title_text);
        mBackBt = (ImageView) findViewById(R.id.back_bt);
        mTvTitle.setText("多选列表");
        dataList = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            dataList.add(new SelectBean("入库点数", false));
        }
        CheckBoxListAdapter adapter = new CheckBoxListAdapter(this, dataList);
        mLvRadio.setAdapter(adapter);
        adapter.setOnItemListener(new CheckBoxListAdapter.ItemClick() {
            @Override
            public void onItemClickListener(int position, SelectBean bean) {
                mReStart.setText("已选("+filterSelected()+")");
            }
        });

        mBackBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finishActivity();
            }
        });
    }

    public int filterSelected(){
        int i = 0;
        for (SelectBean selectBean : dataList) {
            if(selectBean.isSelected){
                i++;
            }
        }
        return i;
    }
}
